home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmigaPlus / Tools / Development / AmigaTalk / general / SlotAdaptor.st < prev    next >
Encoding:
Text File  |  2004-01-31  |  1.4 KB  |  49 lines

  1. " ----------------------------------------------------------------------
  2.   Class SlotAdaptor redirects the value and value: methods to the 
  3.   target by sending instVarAt: and instVarAt:put:, respectively.
  4.  
  5.   When there is no target, the value is always nil; setValue: is a 
  6.   no-op; and value: only notifies the dependents.
  7.  
  8.   The subject is assumed to not send updates.  However, if it uses 
  9.   #at as the aspect and provides the index as the parameter, it will 
  10.   be treated as a change notice an propogated to the dependents of 
  11.   the SlotAdaptor.
  12.   ----------------------------------------------------------------------
  13. "
  14. Class SlotAdaptor :IndexedAdaptor
  15. [
  16.    forIndex: instVarIndex
  17.  
  18.      super setIndex: instVarIndex
  19. |
  20.    setValueUsingTarget: anObject to: newValue
  21.      " Set the value in anObject using instVarAt:put: "
  22.  
  23.      (anObject == nil)
  24.         ifFalse: [anObject instVarAt: (super forIndex) put: newValue]
  25. |
  26.    valueUsingTarget: anObject    
  27.      " Answer the value returned by sending anObject instVarAt: "
  28.  
  29.      (anObject == nil)
  30.        ifFalse: [ ^ anObject instVarAt: (super forIndex)]
  31.        ifTrue:  [ ^ nil ]
  32. |
  33.    printOn: aStream
  34.  
  35.      aStream print: self class.
  36.  
  37.      aStream nextPut: $(.
  38.  
  39.      self target printOn: aStream.
  40.  
  41.      aStream space.
  42.  
  43.      self printPathOn: aStream.
  44.  
  45.      aStream nextPutAll: 'instVarAt: '.
  46.      aStream nextPutAll: (super forIndex) printString.
  47.      aStream nextPut: $).
  48. ]
  49.